<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="用户编号" prop="userId">
        <el-select
          filterable
          v-model="queryParams.userId"
          style="width: 240px"
        >
          <el-option
            v-for="dict in userOptions"
            :key="dict.id"
            :label="dict.phone + '---' + dict.userName"
            :value="dict.id"
          />
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['admin:shangjia:dealOrgShangJia']"
        >分配原始商甲</el-button>
      </el-col>







      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="technologyList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="收取人编号" align="center" prop="userId"  />
      <el-table-column label="日志名称" align="center" prop="logName" />
      <el-table-column label="商甲数量" align="center" prop="logCount" />
      <el-table-column label="收取人姓名" align="center" prop="userName" />
      <el-table-column label="收取人电话" align="center" prop="phone" />

    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改足迹对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="用户编号" prop="userId">
          <el-select
            filterable
            v-model="form.userId"
            style="width: 240px"
          >
            <el-option
              v-for="dict in userOptions"
              :key="dict.id"
              :label="dict.phone + '---' + dict.userName"
              :value="dict.id"
            />
          </el-select>
        </el-form-item>
        <el-form-item :label="title" prop="shangJia">
          <el-input-number
            v-model="form.shangJia"
            :precision="3"
            :step="1000"
            :max="10000"
          ></el-input-number>        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>


    <!-- 添加或修改足迹对话框 -->
    <el-dialog :title="title" :visible.sync="closeOpen" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="用户编号" prop="userId">
          <el-select
            filterable
            v-model="form.userId"
            style="width: 240px"
          >
            <el-option
              v-for="dict in userOptions"
              :key="dict.id"
              :label="dict.phone + '---' + dict.userName"
              :value="dict.id"
            />
          </el-select>
        </el-form-item>
        <el-form-item :label="title" prop="shangJia">
          <el-input-number
            v-model="form.shangJia"
            :precision="3"
            :step="1000"
            :max="10000"
          ></el-input-number>        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitClose">确 定</el-button>
        <el-button @click="closeOpen = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { dealOrgShangJia, dealShangJiaList } from "@/api/admin/shangjia_publish";
import {all } from "@/api/admin/user";

export default {
  name: "source_shangjia",
  data() {
    return {

      // 列表查询标识
      isAccount:3,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      userOptions:[],
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 足迹表格数据
      technologyList: [],
      // 弹出层标题
      title: "分配原始商甲",
      closeOpen:false,
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: null,

        itemId: null,

      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    all().then(res =>{
      this.userOptions = res.data;
    })
  },
  methods: {
    /** 查询足迹列表 */
    getList() {
      this.loading = true;
      dealShangJiaList(this.isAccount,this.queryParams).then(response => {
        this.technologyList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    userBuiFormatter(row){
      this.userOptions.forEach(item =>{
        if (row.busId == item.id){
          return item.phone  + '---' + item.userName
        }
      })
    },
    // 表单重置
    reset() {
      this.form = {
        shangJia: 1000.000,
        userId: null

      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
    },

    handleClose(){
      this.reset();
      this.closeOpen = true;
      this.title = "撤回商甲";
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          dealOrgShangJia(this.form.shangJia,this.form.userId).then(response => {
            if (response.code == 200){
              this.msgSuccess(response.msg);
            }else{
              this.msgError(response.msg)
            }

            this.open = false;
            this.getList();
          });

        }
      });
    },

  }
};
</script>
